using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class MyCustomModules_SearchMe : System.Web.UI.UserControl
{
    private string  _RawURL ;
    string conn = System.Configuration.ConfigurationManager.AppSettings.Get("MSSQLConnectionString");
    DataSet ds = new DataSet();

    protected void Page_Load(object sender, EventArgs e)
    {
        _RawURL = Request.RawUrl;
        if (_RawURL.IndexOf("?") > 0)
            _RawURL = _RawURL.Substring(0, _RawURL.IndexOf("?") );
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        mojoPortal.Data.SqlParameterHelper sph = new mojoPortal.Data.SqlParameterHelper(conn, "usp_SearchUsers", CommandType.StoredProcedure, 5);
        sph.DefineSqlParameter("@Name", SqlDbType.NVarChar, ParameterDirection.Input, drpFilter.SelectedIndex == 1 ? txtSearchFilter.Text : "");
        sph.DefineSqlParameter("@PAN", SqlDbType.NVarChar, ParameterDirection.Input, drpFilter.SelectedIndex == 2 ? txtSearchFilter.Text : "");
        sph.DefineSqlParameter("@UserEmail", SqlDbType.NVarChar, ParameterDirection.Input, drpFilter.SelectedIndex == 3 ? txtSearchFilter.Text : "");
        sph.DefineSqlParameter("@Phone", SqlDbType.NVarChar, ParameterDirection.Input, drpFilter.SelectedIndex==4? txtSearchFilter.Text:"");

        ds = sph.ExecuteDataset();

            if (ds.Tables.Count > 0)
            {
                dgUsers.DataSource = ds.Tables[0];
                dgUsers.DataBind();
            }
     
    }

    protected string GetRefreshURL(object value)
    {
        return _RawURL + "?UserGUID=" + (new Guid( value.ToString())).ToString();
    }
    
}
